% TEST_ID: LANG-EXPAND-0120
% CATEGORY: language/string
% 测试 string 的比较

function test_string_strcmp()

x = 'hello';
y = 'Hello';
z = strcmp(x, y);
assert(~z);

x = {'hello', 'world'};
y = {'hello', 'World'};
z = strcmp(x, y);
assert(z(1));
assert(~z(2));

x = 'hello';
y = 'Hello';
z = strcmpi(x, y);
assert(z);

x = {'hello', 'world'};
y = {'hello', 'World'};
z = strcmpi(x, y);
assert(z(1));
assert(z(2));

assert(~strcmp([], 'abc'));

A = {'abc','desf'};
assert(strcmp(A,1) == [0 0]);

a = {'a','b','c','d',NaN};
b = 'a';
R1 = strcmp(a,b);
assert(R1 == [1 0 0 0 0]);
R2 = strcmp(b,a);
assert(R2 == [1 0 0 0 0]);
R3 = strcmp(b,NaN);
assert(~R3);
R4 = strcmp(a,97);
assert(~R4);

R4 = strcmp('', {'', 3, ' '});
assert(R4 == [1,0,0]);


assert(~strcmpi([], 'abc'));

A = {'abc','desf'};
assert(strcmpi(A,1) == [0 0]);

a = {'A','b','c','d',NaN};
b = 'a';
R1 = strcmpi(a,b);
assert(R1 == [1 0 0 0 0]);
R2 = strcmpi(b,a);
assert(R2 == [1 0 0 0 0]);
R3 = strcmpi(b,NaN);
assert(~R3);
R4 = strcmpi(a,97);
assert(R4 == [0 0 0 0 0]);

R4 = strcmpi('', {'', 3, ' '});
assert(R4 == [1,0,0]);

s.a = 1;
b = {};
strcmp(b, s)
assert(isempty(strcmp(b, s)));


a = {'a', 'b', 'c'};
b = s;
assert(strcmp(a, b) == [0 0 0]);


a = char(zeros(3,0));
b = {'abc'};
assert(isequal(strcmp(a, b), [0; 0; 0]));

a = char(zeros(3,0,3));
b = {'abc'};
assert(isequal(strcmpi(a, b), [0; 0; 0]));

a = char(zeros(3,0));
b = "abc";
assert(isequal(strcmp(a, b), [0; 0; 0]));

a = char(zeros(0, 3));
b = {'abc'};
assert(isequal(strcmp(a, b), false));

a = char(zeros(0,3));
b = {char(zeros(0,4))};
assert(isequal(strcmp(a, b), true));

a = 'abc';
b = {['abc']'};
assert(strcmp(a, b) == [1]);

a = 'Abc';
b = {['abc']'};
assert(strcmpi(a, b) == [1]);

% test char 为高维数组的情况
a = ['abc']';
b = {'abc'};
assert(isequal(strcmp(a,b), [0; 0; 0]));

a = ['abc';'abc';'abc'];
b = {'abc'};
assert(isequal(strcmp(a,b), [1; 1; 1]));

a = ['abc']';
b = 'abc';
assert(strcmp(a, b) == [0]);

a = ['aBc']';
b = 'abC';
assert(strcmpi(a, b) == [0]);

a = ['abc']';
b = ['abc']';
assert(strcmp(a, b) == [1]);

a = ['abc']';
b = {'abc'};
r = strcmp(a, b);
assert(isequal(r, [false;false;false]));

a = ['abC']';
b = "Abc";
r = strcmpi(a, b);
assert(isequal(r, [false;false;false]));

a = ['abc'; 'def'];
b = {'abc'; 'def'};
r = strcmp(a, b);
assert(isequal(r, [true;true]));

a = ['abC'; 'def'];
b = string({'abc'; 'Def'});
r = strcmpi(a, b);
assert(isequal(r, [true;true]));

a = ['abc'; 'def'];
b = {'abc' 'def'};
r = strcmp(a, b);
assert(isequal(r, [true true]));

a = ['abc'; 'def'];
b = ones(3,2);
assert(isequal(strcmp(a, b), [0; 0]));

a = char(zeros(0,3,3));
b = 32;
assert(strcmp(a, b) == 0);

a = char(zeros(0, 3));
b = single([3 4]);
assert(strcmpi(a, b) == 0);

a = ['abc'; 'def'];
b = {'abc' 'def'; 'ghi' 'jkl'};
flag = false;
try
    r = strcmp(a, b);
catch
    flag = true;
end
assert(flag);

a = ['abc'; 'def'];
b = {};
flag = false;
try
    r = strcmp(a, b);
catch
    flag = true;
end
assert(flag);

end